- item_partial = f.object.nature.to_s + '_item_fields'
= field_set :general_informations do
  = f.input :nature, as: :hidden
  = f.input :contract_id, as: :hidden
  .delivery-item
    - if f.object.incoming?
      = f.referenced_association :sender, required: true
      = f.input :purchase_id, as: :hidden
    - elsif f.object.outgoing?
      = f.referenced_association :recipient, required: true, input_html: {data: {product_of_delivery_item: {url: backend_entity_path("RECORD_ID", format: :json)}}}
      = f.input :sale_id, as: :hidden
    = f.referenced_association :address, source: :mails, input_html: {data: {"when-item": "address_id", "when-set-value": "RECORD_VALUE"}}, new: { canal: :mail }
  - if f.object.incoming?
    = f.input :reference_number
    = f.referenced_association :storage, source: :storage, required: true
    = f.input :separated_stock
  = f.referenced_association :responsible, source: :employees, new: { employed: 1 }
  = f.input :with_delivery
  = f.input :delivery_mode, as: :radio_buttons
  #transporter
    = f.referenced_association :transporter, source: :transporters, new: {transporter: 1}
  -#= f.referenced_association :sale
  = f.input :planned_at, required: false
  = f.input :given_at, required: false
  - if f.object.outgoing?
    = f.input :remain_owner
  = f.custom_fields
  = f.attachments
  -# = f.object.errors.inspect

- if f.object.allow_items_update?
  = field_set f.object.class.human_attribute_name(:items) do
    %table.list
      %thead
        %tr
          %th.act
          %th= ParcelItem.human_attribute_name(:product)
          %th= ParcelItem.human_attribute_name(:population)
          - if f.object.incoming?
            %th= ParcelItem.human_attribute_name(:unit_pretax_amount)
          %th= ParcelItem.human_attribute_name(:analysis)

      = f.simple_fields_for :items, f.object.items do |item|
        = render item_partial, f: item
      - if f.object.allow_items_update?
        %tfoot#items_anchor
          %tr.total
            %th{colspan: 4 + (f.object.incoming? ? 1 : 0)}= link_to_add_association :add_item.tl, f, :items, partial: item_partial, 'data-association-insertion-node' => '#items_anchor', 'data-association-insertion-method' => :before, class: "btn primary"
/ -else
/   = field_set f.object.class.human_attribute_name(:items) do
/     = "Items cannot be edited in current parcel state."
